/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Views.GestionRestaurant;

import Controller.Controller;

import Model.Restaurateur;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import javax.swing.AbstractCellEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

/**
 *
 * @author ibrahim
 */
public class RestaurateurEditor extends AbstractCellEditor implements TableCellEditor {
    
    private JComboBox combo;
    
    private DefaultComboBoxModel restComboModel;
    public RestaurateurEditor(Controller controller){
        this.combo = new JComboBox();
        restComboModel = new DefaultComboBoxModel();
        for(Restaurateur rest:controller.getRestauraterurs()){
           restComboModel.addElement(rest.getFname()+" "+ rest.getLname()); 
        }
        combo.setModel(restComboModel);
    }
    

    @Override
    public Object getCellEditorValue() {
        
        return combo.getSelectedItem();
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        
        combo.setSelectedItem(value);
        combo.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                fireEditingStopped();
            }
        });
        return combo;
    }

    @Override
    public boolean isCellEditable(EventObject e) {
        return true;
    }
    
    
}
